#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- python -*-
"""
 gen-logtab.py

 by Jacob Smith <http://code.google.com/p/lua-mpi/>
 Copyright (C) 2009 Jacob Smith, All Rights Reserved

 $Id: gen-logtab.py 11 2009-07-01 08:02:38Z kloptops $
"""

import math;
from util import *

def ispow2d(d):
    _pow = 0;
    while d > 1 and d & 1 == 0:
        _pow += 1;
        d >>= 1;
    if d == 1:
        return _pow;
    return 0;

def zlog(d):
    if d < 2:
        return 0.0;
    return math.log(2) / math.log(ix);

results = []
pack_range = range(1, 65);
for ix in pack_range:
    results.append("{%0.9f, %2d}" % (zlog(ix), ispow2d(ix)))

output = "\n".join(map(lambda ix: "    " + ", ".join(results[ix:(ix + 4)]) + ", -- " + ", ".join(map(lambda x: "%2d" % (x), pack_range[ix:(ix + 4)])), range(0, len(results), 4)));

mpi_file = abspath('..', 'mpi.lua')

zone = Zones()

data = loadraw(mpi_file);
zone.unpack(data);
zone.replace('LOGPOW TAB', output);
packed = zone.pack();
saveraw(mpi_file, packed);
